<template>
    <div>
        <el-dialog top="5%" :title="title" size="large" v-model="editFormVisible" :close-on-click-modal="false">
           <Approve @onApproveSuc="onApproveSuc" :showcontent="showcontent" ref="approve" v-if="ApproveID"></Approve>
            <el-tag v-if="ApproveID"  style="font-size: larger; margin: 10px 0px 10px 10px;">报账信息</el-tag>
            <div style="border: 1px solid #bbb; padding: 20px;">
            <el-form  ref="form" :model="form" :inline="true" :rules="rules" label-width="150px">
                <el-form-item label="类型" placeholder="请选择"  prop="FCostTypeID">
                    <sy-select v-model="form.FCostTypeID"  valueKey="FID" style="width:320px" @change="changetype"
                               optionData="server/setting/CostType.ashx?cmd=GetOptions">
                    </sy-select>
                </el-form-item>
                <el-form-item label="申请人" placeholder="请选择"  prop="FUserID">
                <sy-select v-model="form.FUserID"  valueKey="FID" style="width:320px"
                           optionData="server/system/User.ashx?cmd=GetUserOptions">
                </sy-select>
                </el-form-item>
                <el-form-item label="时间">
                    <el-date-picker type="date"  v-model="form.FDate"  style="width:320px"></el-date-picker>
                </el-form-item>
                <el-form-item label="金额(元)">
                    <el-input type="number" v-model="form.FCost" style="width:320px;"></el-input>
                </el-form-item>
                <el-form-item label="施工费用申请编号" placeholder="请选择"  prop="FCostNo" v-if="showno">
                    <sy-select v-model="form.FCostNo"  valueKey="FNo" style="width:320px"
                               optionData="server/business/ConstructionCost.ashx?cmd=GetOptions">
                    </sy-select>
                </el-form-item>
                <el-form-item label="事由">
                    <el-input type="textarea" v-model="form.FNote" style="width:850px;"></el-input>
                </el-form-item>
            </el-form>
            </div>
                <div slot="footer" class="dialog-footer">
                <el-button @click.native="editFormVisible = false">取 消</el-button>
                <el-button type="primary" v-if="showSave" @click="save" :loading="loading">保存</el-button>
            </div>
      </el-dialog>
    </div>
</template>

<script>
    import util from '../../common/util'
    import mixin from '../../common/mixin'
    import Approve from './Approve.vue'
    import Vue from 'vue'
    export default {
        components:{
            Approve:Approve
        },
        data() {
            return {
                form: {},
                showSave:true,
                rules: {
                   // FName: [{type: "date",name:"FCreateDate",text:"跟进时间", value: null}]
                },
                loading:false,
                editFormVisible:false,
                title:'',
                listLoading:false,
                ApproveID:null,
                showcontent:true,
                fixWhere:'',
                showno:false
            }
        },
        computed: {

        },
        methods: {
            switchLoading(flag){
                this.loading = flag
            },
            _openEdit(record) {
                this.editFormVisible = true
                this.form = Object.assign({},record)
                this.title = '编辑'
                if(record.FCostTypeID==-1){
                    this.showno=true
                }
            },
            _openAdd(record) {
                this.editFormVisible = true
                this.form = {FID:0,FDate:null,FCreateUserID:global.user.FID,FCreateDate:new Date()}
                this.title = '新增'
            },
            _openApprove(record,ApproveID) {
                this.editFormVisible = true;
                this.ApproveID = ApproveID
                this.form = Object.assign({},record);
                if(record.FApproveStatus!=0&&record.FApproveStatus!=-1){
                if((record.FToApprover!=global.user.FID)||record.FApproveStatus==3)
                {
                    this.showSave=false
                    this.showcontent=false
                    this.title='查看'
                }
                else {
                    this.title='审核'
                }
                }
                if(record.FApproveStatus==0||record.FApproveStatus==-1) {
                    this.title='提交审核'
                }

                this.$nextTick(()=>{
                    this.$refs.approve._init(record,ApproveID);
                })
                if(record.FCostTypeID==-1){
                    this.showno=true
                }
            },
            save:function () {
                if(this.form.FCostTypeID==-1){
                    if(this.form.FCostNo==""){
                        util.msgWarning("请选择施工费用申请编号")
                        return;
                    }
                }
                util.post("server/business/CostApply.ashx?cmd=Save",this.form,this.switchLoading,result=> {
                    util.msgSuc("保存成功")
                    if(!this.ApproveID) {
                        this.editFormVisible = false
                        this.$emit("onSaveSuc", this.form)
                    }
                })
            },
            onApproveSuc()
            {
                global.bus.$emit('RefreshMsgCount')
                this.editFormVisible = false
                this.$emit("onSaveSuc", this.form)
            },
            changetype(val){
                if(val==-1){
                    this.showno=true
                }else
                {
                    this.showno=false
                    this.form.FCostNo=''
                }
            }
        },
        mounted() {

        }
    }
</script>
